package com.gxpt.app;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.kaopiz.kprogresshud.KProgressHUD;


/**
 *
 * http://www.tuicool.com/articles/7jIr6fy
 * **/
public abstract class BaseActivity extends Activity{

    public KProgressHUD hud;

    public Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this;
        MyApp.getInstance().addActivity(this);

        hud = KProgressHUD.create(this)
                .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
                .setLabel(getResources().getString(R.string.alert_progress))
                .setCancellable(true);
//        //        scheduleDismiss();
//        //        hud.show();
    }

    public void jumpActivity(Class toClass,Boolean isFinishMy){
        Intent intent = new Intent(context, toClass);
        context.startActivity(intent);
        if(isFinishMy){
            finish();
        }
    }

    public void jumpActivity(Class toClass,Bundle data,Boolean isFinishMy){
        Intent intent = new Intent(context, toClass);
        intent.putExtra("DATA",data);
        context.startActivity(intent);
        if(isFinishMy){
           finish();
        }
    }

    public void closeActivity(){
        finish();
    }


    public void closeOtherActivity(String ActivityName){
        MyApp.getInstance().closeOneActivity(ActivityName);
    }
    public abstract void initView();
    public abstract void initData();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MyApp.getInstance().removeActivity(this);
    }

    protected void toNewActivty(Class<?> cls) {
        Intent go = new Intent(context,cls);
        startActivity(go);

    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    //
//    @Override
//    protected void onResume() {
//        super.onResume();
//    }
//
//    private void scheduleDismiss() {
//        Handler handler = new Handler();
//        handler.postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                hud.dismiss();
//            }
//        }, 10000);
//    }

}
